package cn.gao;

import cn.gao.listener.FileListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;

import static java.lang.Thread.sleep;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: GaoXu
 * @Date: 2022/05/20/13:37
 * @Description:
 */
public class Main {
    public static void main(String[] args) throws IOException {
        new FileListener();
        new Main();
    }

    public Main() throws IOException {
        init();
    }

    public void init() throws IOException {
        this.setTray();
    }

    public void setTray() throws IOException {

        if (SystemTray.isSupported()) {//判断当前平台是否支持托盘功能

            //创建托盘实例

            SystemTray tray = SystemTray.getSystemTray();

            //创建托盘图标：1.显示图标Image 2.停留提示text 3.弹出菜单popupMenu 4.创建托盘图标实例

            //1.创建Image图像

            URL resource = this.getClass().getResource("/icon.png");//获取托盘图标

            ImageIcon icon = new ImageIcon(resource);

            //2.停留提示text

            String text = "GTidy文件整理";

            //3.弹出菜单popupMenu

            PopupMenu popMenu = new PopupMenu();

            popMenu.setFont(new Font("宋体", Font.ROMAN_BASELINE, 12));


            MenuItem itmExit = new MenuItem("Exit");
            itmExit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Exit();
                }

            });
            popMenu.add("GA666666");
            popMenu.addSeparator();

            popMenu.add(itmExit);

            //创建托盘图标

            TrayIcon trayIcon = new TrayIcon(icon.getImage(), text, popMenu);

            trayIcon.setImageAutoSize(true);

            //将托盘图标加到托盘上

            try {

                tray.add(trayIcon);

            } catch (AWTException e1) {

                e1.printStackTrace();

            }

        }

    }


    public void Exit() {
        System.exit(0);
    }

}
